{% extends 'warehouse/base.html' %}

{% block title %}商品列表{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <h1>商品列表</h1>
        
        {% if messages %}
            {% for message in messages %}
                <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                    {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            {% endfor %}
        {% endif %}
        
        <div class="card">
            <div class="card-header">
                <h3>所有商品</h3>
                {% if 'goods_create' in user_permissions %}
                <a href="{% url 'warehouse:goods_create' %}" class="btn btn-primary float-end">创建商品</a>
                {% endif %}
            </div>
            <div class="card-body">
                <p><strong>数据库状态:</strong> {{ db_status }}</p>
                
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>商品名称</th>
                            <th>规格</th>
                            <th>单位</th>
                            <th>保质期</th>
                            <th>最小库存</th>
                            <th>最大库存</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for goods in goods_list %}
                        <tr>
                            <td>{{ goods.name }}</td>
                            <td>{{ goods.specification }}</td>
                            <td>{{ goods.unit }}</td>
                            <td>
                                {% if goods.shelf_life %}
                                    {{ goods.shelf_life }}天
                                {% else %}
                                    无保质期
                                {% endif %}
                            </td>
                            <td>{{ goods.min_stock }}</td>
                            <td>{{ goods.max_stock }}</td>
                            <td>
                                <a href="{% url 'warehouse:goods_detail' goods.id %}" class="btn btn-sm btn-info">详情</a>
                                {% if 'goods_update' in user_permissions %}
                                <a href="{% url 'warehouse:goods_edit' goods.id %}" class="btn btn-sm btn-warning">编辑</a>
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="7">暂无商品数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="mt-3">
            <a href="{% url 'warehouse:dashboard' %}" class="btn btn-secondary">返回仪表盘</a>
        </div>
    </div>
</div>
{% endblock %}